<?php
/**
 * A simple description for this script
 *
 * PHP Version 5.2.0 or Upper version
 *
 * @package    Paylog
 * @author     Hidehito NOZAWA aka Suin <http://suin.asia>
 * @copyright  2010 Hidehito NOZAWA
 * @license    http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2
 *
 */

class Paylog_Controller_Tags extends Paylog_Abstract_Controller
{
	protected $groupHand = null;
	protected $groupId = null;

	public function __construct()
	{
		parent::__construct();

		$this->groupHand = new Paylog_Object_GroupHandler;
		$this->groupId   = Paylog::get('group_id');
	}

	public function main()
	{
		$this->_validateAccess();
		$this->_default();
	}

	protected function _default()
	{
		$groupObj = $this->groupHand->load($this->groupId);

		$this->output['total'] = count($groupObj->tagObjs);

		$this->output['group'] = array(
			'id'     => $groupObj->getVar('id'),
			'name'   => $groupObj->getVar('name'),
			'weight' => $groupObj->getVar('weight'),
		);

		$this->output['tags'] = array();

		foreach ( $groupObj->tagObjs as $tagObj )
		{
			$this->output['tags'][] = array(
				'id'     => $tagObj->getVar('id'),
				'name'   => $tagObj->getVar('name'),
				'weight' => $tagObj->getVar('weight'),
			);
		}

		$this->_view();
	}

	protected function _validateAccess()
	{
		if ( $this->groupId < 0 )
		{
			Paylog::redirect("Group ID is invalid.");
		}

		if ( !$this->groupHand->isIdExists($this->groupId) )
		{
			Paylog::redirect("Such a group does not exist.");
		}
	}
}

?>
